package com.tron.dobest.aop;

import com.tron.dobest.mybatisplus.entity.User;
import com.tron.dobest.mybatisplus.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@Api(tags = "AOP测试")
@RestController
@Slf4j
public class TronAopTestController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "非环绕切面")
    @GetMapping("/aopTest01")
    public Object aopTest01() {
        log.info("======切面测试======");
        HashMap<String, Object> map = new HashMap<>();
        map.put("message", "切面测试");
        System.out.println(1/0);
        return map;
    }

    @ApiOperation(value = "环绕切面")
    @GetMapping("/aopTest02")
    public Object aopTest02() {
        List<User> list = userService.list();
        log.info("======切面测试======");
        HashMap<String, Object> map = new HashMap<>();
        map.put("message", "切面测试");
        map.put("list", list);
        return map;
    }


    @GetMapping("/aopTest03")
    public Object aopTest03() {
        return "success";
    }

    @GetMapping("/aopTest04")
    protected Object aopTest04() {
        return "success";
    }
}
